package com.example.home.pet.activity;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.pet.adapter.DoctorListAdapter;
import com.example.home.pet.bean.DoctorListBean;
import com.example.home.tool.OKHttpTool;

public class PetCartDetailActivity extends AppCompatActivity {

    private String petdotId;
    private RecyclerView rcvList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pet_cart_detail);
        Intent intent = getIntent();
        petdotId = intent.getStringExtra("petdotId");


        rcvList = findViewById(R.id.rcv_list);


        getDoctorList();
    }

    private void getDoctorList() {
        OKHttpTool.doNetRequest("prod-api/api/pet-hospital/pet-doctor/list?typeId="+petdotId,
                OKHttpTool.GET,
                DoctorListBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        DoctorListBean doctorListBean = (DoctorListBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                bindDoctorList(doctorListBean);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void bindDoctorList(DoctorListBean doctorListBean) {
        DoctorListAdapter doctorListAdapter = new DoctorListAdapter(PetCartDetailActivity.this,doctorListBean.getRows());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(PetCartDetailActivity.this);
        rcvList.setAdapter(doctorListAdapter);
        rcvList.setLayoutManager(linearLayoutManager);
    }
}